package com.yangrui.app.server;

import com.yangrui.app.entity.LessonLog;
import com.yangrui.app.util.LogUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.Future;

@Slf4j
@Component
public class LogServer {

    public Future<Void> saveLog(){
        List<LessonLog> logLines = LogUtil.parseLog("D:\\java-lesson\\log\\my1.log");
        logLines.forEach(logLine -> log.info("logLine: {}", log));

        return  new AsyncResult<>(null);
    }

    //每天凌晨12点调用saveLog方法
    @Scheduled(cron = "0 31 15 * * *")
    public void executeSaveLog(){
        log.info("saveLog executed");
        Future<Void> voidFuture = saveLog();
        while (voidFuture.isDone()){
            log.info("saveLog is not done");
            break;
        }

    }
}
